/*
 * @Date: 2023-10-22 16:54:31
 * @LastEditTime: 2023-10-23 23:42:41
 * 介绍:
 */
import { defaHttp, Api } from "../index";
import type { InitState } from "@/pages/metting/components/mix";

/**创建房间 */
export async function apiCreateRoom(
  data: CreateRoom.Req
): Promise<CreateRoom.Res | undefined> {
  const res = await defaHttp.post<Api.Res<CreateRoom.Res>>(
    "/create/token",
    data,
    {
      mode: {
        failMessage: true,
        loadingMessage: true,
      },
    }
  );
  if (!res.status) return;
  return res.data;
}
/**创建房间 */
export namespace CreateRoom {
  export interface Req {
    code: string;
  }
  export interface Res {
    token: string;
    user_id: number;
    channel: StrNumber;
    appid: string;
    turn: Turn;
    list_id: string;
    settings?: InitState;
  }
  export interface Turn {
    login_code: string;
  }
}

/**加入房间 */
export async function apiJoinRoom(
  data: JoinRoom.Req
): Promise<JoinRoom.Res | undefined> {
  const res = await defaHttp.post<Api.Res<JoinRoom.Res>>(
    "/join/channel",
    data,
    {
      mode: {
        failMessage: true,
        loadingMessage: true,
      },
    }
  );
  if (!res.status) return;
  return res.data;
}
/**加入房间 */
export namespace JoinRoom {
  export interface Req {
    channel: string;
  }
  export interface Res {
    token: string;
    user_id: number;
    appid: string;
    manger: number;
    list_id: string;
    settings?: InitState;
    login_code: string;
  }
}

/**删除房间 */
export async function apiDelRoom(
  data: DelRoom.Req
): Promise<DelRoom.Res | undefined> {
  const res = await defaHttp.post<Api.Res<DelRoom.Res>>(
    "/delete/channel",
    data,
    {
      mode: {
        failMessage: true,
      },
    }
  );

  if (!res.status) return;
  return res.data;
}
/**删除房间 */
export namespace DelRoom {
  export interface Req {
    channel: string;
  }
  export interface Res {}
}

/**发送评论 */
export async function apiSendComment(
  data: SendComment.Req
): Promise<SendComment.Res | undefined> {
  data = { ...data, content_type: 0, _agent_id: 0 };
  const res = await defaHttp.post<Api.Res<SendComment.Res>>(
    "/im/message/textMsg",
    data,
    {
      mode: {
        failMessage: true,
      },
    }
  );
  if (!res.status) return;
  return res.data;
}
/**发送评论 */
export namespace SendComment {
  export interface Req {
    list_id: string;
    content: string;
    content_type?: number;
    _agent_id?: number;
  }

  export interface Res {}
}
